package com.ruoyi.lock.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.lock.domain.APeriodicPassword;
import com.ruoyi.lock.service.IAPeriodicPasswordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 周期性密码 控制器
 * 
 * @author ruoyi
 */
@RestController
@RequestMapping("/lock/periodic/password")
public class APeriodicPasswordController extends BaseController {
    @Autowired
    private IAPeriodicPasswordService aPeriodicPasswordService;

    /**
     * 查询周期性密码列表
     */
    @PreAuthorize("@ss.hasPermi('lock:password:list')")
    @GetMapping("/list")
    public AjaxResult list(APeriodicPassword aPeriodicPassword) {
        List<APeriodicPassword> list = aPeriodicPasswordService.selectAPeriodicPasswordList(aPeriodicPassword);
        return AjaxResult.success(list);
    }

    /**
     * 获取周期性密码详细信息
     */
    @PreAuthorize("@ss.hasPermi('lock:password:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(aPeriodicPasswordService.selectAPeriodicPasswordById(id));
    }
    
    /**
     * 按设备MAC和房间ID查询周期性密码列表
     */
    @GetMapping("/listByMacAndHomeId")
    public AjaxResult listByMacAndHomeId(String deviceMac, Long homeId, Boolean showExpired) {
        List<APeriodicPassword> list = aPeriodicPasswordService.selectPasswordsByMacAndHomeId(deviceMac, homeId, showExpired);
        return AjaxResult.success(list);
    }

    /**
     * 新增周期性密码
     */
    @PreAuthorize("@ss.hasPermi('lock:password:add')")
    @Log(title = "周期性密码", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody APeriodicPassword aPeriodicPassword) {
        return toAjax(aPeriodicPasswordService.insertAPeriodicPassword(aPeriodicPassword));
    }

    /**
     * 修改周期性密码
     */
    @PreAuthorize("@ss.hasPermi('lock:password:edit')")
    @Log(title = "周期性密码", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody APeriodicPassword aPeriodicPassword) {
        return toAjax(aPeriodicPasswordService.updateAPeriodicPassword(aPeriodicPassword));
    }
    
    /**
     * 更新密码备注
     */
    @PutMapping("/updateRemarks/{id}")
    public AjaxResult updateRemarks(@PathVariable("id") Long id, String remarks) {
        return toAjax(aPeriodicPasswordService.updatePasswordRemarks(id, remarks));
    }

    /**
     * 删除周期性密码
     */
    @PreAuthorize("@ss.hasPermi('lock:password:remove')")
    @Log(title = "周期性密码", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(aPeriodicPasswordService.deleteAPeriodicPasswordByIds(ids));
    }
} 